function autoupdate() {
	var t = setTimeout("autoupdate()", 240000); // ogni 4 minuti

	$.ajax({ 
		type: "POST", 
		url: "/include/php/jquery/autoupdate_utente.php", 
		cache: false,
		success: function(message) {
			n = message.split(",");
			aggiorna_notifica("bacheca", n[0]);
			aggiorna_notifica("amici", n[1]);
			aggiorna_notifica("commenti", n[2]);
			aggiorna_notifica("raccomandazioni", n[3]);
			aggiorna_notifica("preferiti", n[4]);
			aggiorna_notifica("messaggi", n[5]);
			tot_new = n[0] + n[1] + n[2] + n[3] + n[4] + n[5];
			if (tot_new > 0) {
				$("#a1 img.handle_icon").addClass("alert");
				suono =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">';
				suono += '<param name="wmode" value="transparent" /><embed wmode="transparent" width="1" height="1" src="/include/swf/singlemp3player.swf?file=/media/audio/new_notifica.mp3&autoStart=true&repeatPlay=false&songVolume=70" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
				$("#suono_notifiche").html(suono);
			}
			else {
				$("#a1 img.handle_icon").removeClass("alert");
				$("#suono_notifiche").html("");
			}
		} 
	}); 

} 

function aggiorna_notifica(quale, quanto) {
	if (quanto > 0) {
		$("#notifica_" + quale).removeClass("notifica_chiaro");
		$("#notifica_" + quale).addClass("notifica");
		$("#new_" + quale).html("(" + quanto + ")");
		if (quale == "messaggi" && $("#notifica_" + quale).attr("href").indexOf("?new=1") < 0)
			$("#notifica_" + quale).attr("href", $("#notifica_" + quale).attr("href") + "?new=1");
		else if (quale != "amici" && quale != "messaggi" && $("#notifica_" + quale).attr("href").indexOf("&tipo=1") < 0)
			$("#notifica_" + quale).attr("href", $("#notifica_" + quale).attr("href") + "&tipo=1");
	}
	else {
		$("#notifica_" + quale).removeClass("notifica");
		$("#notifica_" + quale).addClass("notifica_chiaro");
		$("#notifica_" + quale).attr("href", $("#notifica_" + quale).attr("href").replace("?new=1",""));
		$("#notifica_" + quale).attr("href", $("#notifica_" + quale).attr("href").replace("&tipo=1",""));
		$("#new_" + quale).html("");
	}
}

$(document).ready(function() {

	// autoaggiornamento
	setTimeout("autoupdate()", 240000);

});
